﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HUST.JackRiver.Demo.Doc2Text
{
    public class Doc2TextConverter
    {
        private string filePath;

        public Doc2TextConverter(string FilePath)
        {
            filePath = FilePath;
        }

        public string Convert()
        {
            int index=filePath.LastIndexOf('.');
            string filetype=filePath.Substring(index+1,filePath.Length-index-1);
            string result = "";
            //判断文件类型并转换
            if (filetype == "doc" || filetype == "docx")
            {
                Document doc = new DocDocument(filePath);
                result = doc.ToPlainText().TextContent;
            }
            else
            {
                if (filetype == "xls" || filetype == "xlsx")
                {
                    Document doc = new XlsDocument(filePath);
                    result = doc.ToPlainText().TextContent;
                }
                else
                {
                    if (filetype == "ppt" || filetype == "pptx")
                    {
                        Document doc = new PPTDocument(filePath);
                        result = doc.ToPlainText().TextContent;
                    }
                    else
                    {
                        if (filetype == "pdf")
                        {
                            Document doc = new PDFDocument(filePath);
                            result = doc.ToPlainText().TextContent;
                        }
                    }
                }
            }
            return result;
        }
    }
}
